// 测试用户数据 - 具有所有权限的超级管理员
// 根据路由配置分析得出的完整权限列表

// 从路由配置中提取的所有角色
const allRoles = [
  'admin',    // 管理员角色
  'user'      // 普通用户角色
];

// 从路由配置中提取的所有权限
const allPermissions = [
  'user:read',        // 用户管理 - 查看用户
  'survey:read',      // 问卷管理 - 查看问卷
  'survey:create',    // 问卷管理 - 创建问卷
  'survey:edit',      // 问卷管理 - 编辑问卷
  'discussion:read'   // 讨论管理 - 查看讨论
];

// 超级管理员用户对象
export const superAdminUser = {
  id: '1',
  username: 'superadmin',
  nickname: '超级管理员',
  avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=superadmin',
  roles: allRoles,                    // 拥有所有角色
  permissions: allPermissions,        // 拥有所有权限
  email: 'superadmin@example.com',
  phone: '13800138000',
  department: '技术部',
  position: '系统管理员',
  lastLoginTime: new Date().toISOString(),
  status: 'active'
};

// 管理员用户对象（只有admin角色）
export const adminUser = {
  id: '2',
  username: 'admin',
  nickname: '管理员',
  avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=admin',
  roles: ['admin'],
  permissions: [
    'user:read',
    'survey:read',
    'survey:create',
    'survey:edit',
    'discussion:read'
  ],
  email: 'admin@example.com',
  phone: '13800138001',
  department: '管理部',
  position: '管理员',
  lastLoginTime: new Date().toISOString(),
  status: 'active'
};

// 普通用户对象
export const normalUser = {
  id: '3',
  username: 'user',
  nickname: '普通用户',
  avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=user',
  roles: ['user'],
  permissions: [
    'survey:read',
    'survey:create',
    'survey:edit',
    'discussion:read'
  ],
  email: 'user@example.com',
  phone: '13800138002',
  department: '业务部',
  position: '业务员',
  lastLoginTime: new Date().toISOString(),
  status: 'active'
};

// 测试用的JWT Token（模拟）
export const testToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJzdXBlcmFkbWluIiwicm9sZXMiOlsiYWRtaW4iLCJ1c2VyIl0sInBlcm1pc3Npb25zIjpbInVzZXI6cmVhZCIsInN1cnZleTpyZWFkIiwic3VydmV5OmNyZWF0ZSIsInN1cnZleTplZGl0IiwiZGlzY3Vzc2lvbjpyZWFkIl0sImlhdCI6MTcwNDAwMDAwMCwiZXhwIjoxNzA0MDg2NDAwfQ.test-signature';

// 设置测试用户到localStorage的辅助函数
export const setTestUser = (userType = 'superadmin') => {
  let userData, token;
  
  switch (userType) {
    case 'superadmin':
      userData = superAdminUser;
      token = testToken;
      break;
    case 'admin':
      userData = adminUser;
      token = testToken;
      break;
    case 'user':
      userData = normalUser;
      token = testToken;
      break;
    default:
      userData = superAdminUser;
      token = testToken;
  }
  
  // 设置到localStorage
  localStorage.setItem('userInfo', JSON.stringify(userData));
  localStorage.setItem('token', token);
  
  console.log(`已设置测试用户: ${userData.nickname}`, userData);
  return userData;
};

// 清除测试数据的辅助函数
export const clearTestUser = () => {
  localStorage.removeItem('userInfo');
  localStorage.removeItem('token');
  localStorage.removeItem('refreshToken');
  console.log('已清除测试用户数据');
};

// 权限分析报告
export const permissionAnalysis = {
  // 路由权限分析
  routes: {
    main: { roles: [], permissions: [] }, // 数据总览 - 无特殊权限要求
    userManagement: { roles: ['admin'], permissions: ['user:read'] },
    userProfile: { roles: [], permissions: [] }, // 用户资料 - 无特殊权限要求
    surveyList: { roles: ['admin', 'user'], permissions: ['survey:read'] },
    addSurvey: { roles: ['admin', 'user'], permissions: ['survey:create'] },
    discussionList: { roles: ['admin', 'user'], permissions: ['discussion:read'] },
    editQuestionare: { roles: ['admin', 'user'], permissions: ['survey:edit'] }
  },
  
  // 角色权限矩阵
  roleMatrix: {
    admin: {
      canAccess: ['main', 'userManagement', 'userProfile', 'surveyList', 'addSurvey', 'discussionList', 'editQuestionare'],
      permissions: ['user:read', 'survey:read', 'survey:create', 'survey:edit', 'discussion:read']
    },
    user: {
      canAccess: ['main', 'userProfile', 'surveyList', 'addSurvey', 'discussionList', 'editQuestionare'],
      permissions: ['survey:read', 'survey:create', 'survey:edit', 'discussion:read']
    }
  }
};

// 默认导出超级管理员
export default superAdminUser;
